package com.it.chinamobileai.tool;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.it.chinamobileai.domain.CommunicationPackages;
import com.it.chinamobileai.service.ICommunicationPackagesService;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class MyTool {
    @Autowired
    private ICommunicationPackagesService communicationPackageService;

    @Tool(description = "套餐数据的查询")
    public List<CommunicationPackages> getCommunicationPackage(@ToolParam(required = false,description = "查询条件") CommunicationPackageQuery query){
        if(query==null){
            return communicationPackageService.list();
        }
        QueryWrapper<CommunicationPackages> qw = new QueryWrapper<>();
        qw.le(query.getMonthlyRent()!=null,"monthly_rent",query.getMonthlyRent());
        if(query.getDataVolume()!=null){
            qw.ge("data_volume",query.getDataVolume());
        }else {
            qw.eq("data_volume",null);
        }
        qw.ge(query.getCallDuration()!=null,"call_duration",query.getCallDuration());
//        List<CommunicationPackageQuery.Sort> sorts = query.getSorts();
//        if(CollUtil.isNotEmpty(sorts)){
//            for (CommunicationPackageQuery.Sort sort : sorts) {
//                qw.orderBy(true,sort.getIsAsc(),sort.getField());
//            }
//        }
        List<CommunicationPackages> list = null;
        try {
            list = communicationPackageService.list(qw);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
